<?php

/**
 * Yii Controller FacebookController
 *
 * @author trongkhoi
 * @since Apr 28, 2014 - 11:17:35 PM
 */
class FacebookController extends BackController
{

    public $modelName = 'Facebook';

    public function actionIndex()
    {
        //Thu vien Facebook SDK
        Yii::import('application.extensions.facebook_sdk.facebook');
        $fb = new Facebook(Yii::app()->params['facebook']);//Config
        $params = array(
            // this is the access token for Fan Page
            "access_token" => "CAACYHYyWcnIBAMK1y2tqiRKx8bBXGFFzjdUamOlMZCBJrTSL8ic1z5sZBarBi3DbTh9mMUz3aiZCAQRNHvOmcMxLZC53FNtkrVCq8rZCLsyjbQVZAt8o7S6Rd1UT0LK7AkgyZAlu11MC9rWND8eZBiKjjiYjwmBMLWko7k6GGPZCREehKRNFCsyM1Ll7sFb1hXycZD",
            "message" => "Here is a blog post about auto posting on Facebook using PHP #php #facebook",
            "link" => "http://www.pontikis.net/blog/auto_post_on_facebook_with_php",
            "picture" => "http://i.imgur.com/lHkOsiH.png",
            "name" => "How to Auto Post on Facebook with PHP",
            "caption" => "www.pontikis.net",
            "description" => "Automatically post on Facebook with PHP using Facebook PHP SDK. How to create a Facebook app. Obtain and extend Facebook access tokens. Cron automation."
        );

        try
        {
            // 466400200079875 is Facebook id of Fan page https://www.facebook.com/pontikis.net
            $ret = $fb->api('/274360522679892/feed', 'POST', $params);
            echo 'Successfully posted to Facebook Fan Page';
        }
        catch (Exception $e)
        {
            echo $e->getMessage();
        }
    }

}

/**
     * End file Facebook2Controller
     */
    